package com.lucy.flow.validator;

import cn.hutool.core.lang.Validator;
import com.lucy.flow.model.BaseModel;
import com.lucy.flow.model.EndModel;
import com.lucy.flow.model.FlowModel;
import com.lucy.flow.model.StartModel;

import javax.validation.ConstraintValidator;
import javax.validation.ConstraintValidatorContext;
import java.util.List;

/**
 * @author jsq
 * 流程model 校验器
 */
public class IsFlowModelValidator implements ConstraintValidator<IsFlowModel, Object> {
    @Override
    public void initialize(IsFlowModel constraintAnnotation) {
        ConstraintValidator.super.initialize(constraintAnnotation);
    }

    @Override
    public boolean isValid(Object o, ConstraintValidatorContext constraintValidatorContext) {
        FlowModel flowModel = (FlowModel) o;
       // List<BaseModel> nodeList = flowModel.getNodeList();
        StartModel startModel = flowModel.getStartModel();
        EndModel endModel = flowModel.getEndModel();
        if (Validator.isEmpty(startModel) || Validator.isEmpty(endModel)){
            return false;
        }
        if (Validator.isEmpty(flowModel.getFlowId()) || Validator.isEmpty(flowModel.getFlowName())){
            return false;
        }
        return true;
    }
}
